package com.ly.algorithm.offerpointer;
import	java.util.stream.Collectors;

import java.util.Arrays;


/**
 * @Classname Offer45
 * @Description
 *
 * 输入一个非负整数数组，把数组里所有数字拼接起来排成一个数，打印能拼接出的所有数字中最小的一个。
 *
 *  
 *
 * 示例 1:
 *
 * 输入: [10,2]
 * 输出: "102"
 * 示例 2:
 *
 * 输入: [3,30,34,5,9]
 * 输出: "3033459"
 *
 *
 * @Date 2021/1/31 16:18
 * @Author 冷心影翼
 */
public class Offer45 {

    public static void main(String[] args) {
        Solution45 solution45 = new Solution45();
        System.out.println(solution45.minNumber(new int[]{3, 30, 34, 5, 9}));
    }
}


class Solution45 {
    public String minNumber(int[] nums) {
        return Arrays.stream(nums).boxed().map(String::valueOf)
            .sorted((o1, o2) -> (o1+o2).compareTo(o2+o1)).collect(Collectors.joining(""));
    }

}